﻿#include "decryption.h"

Decryption::Decryption(QObject *parent)
    : QObject{parent}
{}

void Decryption::createDecryptionCode(QString year, QString month, QString day, QString hour, QString minute, QString order, QString custom)
{
    int re_year = year.toInt();
    int re_month = month.toInt();
    int re_day = day.toInt();
    int re_hours = hour.toInt();
    int re_minutes = minute.toInt();
    int re_order = order.toInt();
    int re_custom = custom.toInt();

    // qDebug()<<"年： "<<re_year;
    // qDebug()<<"月： "<<re_month;
    // qDebug()<<"日： "<<re_day;
    // qDebug()<<"时： "<<re_hours;
    // qDebug()<<"分： "<<re_minutes;
    // qDebug()<<"序列号： "<<re_order;
    // qDebug()<<"厂家码： "<<re_custom;

    QDateTime datetime = QDateTime::currentDateTime();
    QString currentDate = datetime.toString("dd");

    QString s1,s2,s3,s4,s5,s6,s7,s8,s9;

    s1 = QString("%1").arg((re_year + 6),4,16,QLatin1Char('0'));
    s2 = QString("%1").arg((re_month + re_day + 10),2,16,QLatin1Char('0'));
    s3 = QString("%1").arg((re_day * 2 + 20),2,16,QLatin1Char('0'));
    s4 = QString("%1").arg((re_hours + 12),2,16,QLatin1Char('0'));
    s5 = QString("%1").arg((re_minutes + 10),2,16,QLatin1Char('0'));
    s6 = QString("%1").arg((re_order + 21),4,16,QLatin1Char('0'));
    s7 = QString("%1").arg((re_custom + 2),4,16,QLatin1Char('0'));
    s8 = QString("%1").arg((currentDate.toInt()+ 28),2,16,QLatin1Char('0'));
    s9 = QString("%1").arg((re_order + re_custom),0,16);

    // QString result = s1.toUpper() +'_'+ s2.toUpper() +'_' + s3.toUpper() +'_' + s4.toUpper() +'_'+s5.toUpper() +'_' +
    //                  s6.toUpper() +'_'+ s7.toUpper() +'_'+ s8.toUpper() +'_'+ s9.toUpper();
    QString result = s1.toUpper() +'_'+ s2.toUpper()  + s3.toUpper() +'_' + s4.toUpper() +s5.toUpper() +'_' +
                     s6.toUpper() +'_'+ s7.toUpper() +'_'+ s8.toUpper() + s9.toUpper();

    // qDebug()<<"---------------------";
    // qDebug()<<"---------------------";
    // qDebug()<<"---------------------";


    // qDebug()<<"结果：    ";
    // qDebug()<<result;

    setEn_Result(result);
}

QString Decryption::en_Result() const
{
    return m_en_Result;
}

void Decryption::setEn_Result(const QString &newEn_Result)
{
    if (m_en_Result == newEn_Result)
        return;
    m_en_Result = newEn_Result;
    emit en_ResultChanged();
}
